package com.biglead.orderservice.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.biglead.common.pojo.GoodsInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface GoodsInfoMapper extends BaseMapper<GoodsInfo> {
    // 扣库存 Mapper 文件
    @Update("UPDATE tb_goods SET goods_stock = #{goodsStock, jdbcType = INTEGER},  goods_sale = #{goodsSale,jdbcType = INTEGER} WHERE id = #{id, jdbcType = INTEGER}")
    boolean updateStockById(GoodsInfo goodsInfo);

    //乐观锁更新数据库
    @Update("UPDATE tb_goods SET goods_stock =goods_stock-1,goods_sale=goods_sale+1, version = version+1 WHERE id = #{id, jdbcType = INTEGER} AND version = #{version, jdbcType = INTEGER}")
    boolean updateStockByOptimistic(GoodsInfo goodsInfo);
}
